/*
 * @lc app=leetcode.cn id=203 lang=golang
 *
 * [203] 移除链表元素
 */

// @lc code=start
/**
 * Definition for singly-linked list.
 * type ListNode struct {
 *     Val int
 *     Next *ListNode
 * }
 */
func removeElements(head *ListNode, val int) *ListNode {
	dn:=&ListNode{Next:head}
	prev:=dn
	for prev.Next!=nil{
		if prev.Next.Val==val{
			tmp:=prev.Next
			prev.Next = prev.Next.Next
			tmp.Next = nil
		}else{
			prev  = prev.Next
		}
	}
	return dn.Next
}

// @lc code=end

